from typing import List


class Solution:
    def validSquare(self, p1: List[int], p2: List[int], p3: List[int], p4: List[int]) -> bool:
        ps = [p2,p3,p4]
        ds = [
            self.getDistance(p1,p2),
            self.getDistance(p1,p3),
            self.getDistance(p1,p4)
        ]
        l = self.findLongest(ds)
        # print(ds,l)
        if l is False:
          return False
        for i in range(0, 3):
          if i == l:
            a = ps[i]
            b = ps[(i + 1) % 3]
            c = ps[(i + 2) % 3]
            d1 = self.getDistance(a, b)
            d2 = self.getDistance(a, c)
            if self.getDistance(b, c) == ds[l] and d1 == d2 :
              return True
        return False
        
    def getDistance(self, a, b):
        return ((a[0] - b[0]) ** 2 + (a[1] - b[1]) **2)
    
    def findLongest(self, ds):
        if ds[0]== ds[1] and ds[0] == ds[2]:
            return False
        for i in range(0, 3):
            a = ds[i]
            b = ds[(i + 1) % 3]
            c = ds[(i + 2) % 3]
            print(a,b,c)
            if c == b:
                if a <= c:
                    return False
                #print('**',c**2,b**2,a**2)
                if c + b  == a :
                    return i
               
        return False